package com.app.util.date;

public class TimeUtil {

	/**
	 * 格式化时间 HH mm ss ms
	 * 
	 * @param timeCount
	 * @param format
	 * @return
	 */
	public static String format(long timeCount, String format) {
		long HH = 0;
		long _HH = 0;
		long mm = 0;
		long _mm = 0;
		long ss = 0;
		long ms = 0;
		String str = format;
		if (format.indexOf("HH") > -1) {
			_HH = (int) (timeCount % (1000 * 60 * 60));
			HH = (int) (timeCount / (1000 * 60 * 60));
			_mm = (_HH % (1000 * 60));
			mm = (_HH / (1000 * 60));
			ss = (_mm / 1000); 
			ms = (_mm % 1000);
			str = str.replaceFirst("HH", String.valueOf(HH));
			str = str.replaceFirst("mm", String.valueOf(mm));
			str = str.replaceFirst("ss", String.valueOf(ss));
			str = str.replaceFirst("ms", String.valueOf(ms));
		} else if (format.indexOf("mm") > -1) {
			_mm = (timeCount % (1000 * 60));
			mm = (timeCount / (1000 * 60));
			ss = (_mm / 1000);
			ms = (_mm % 1000);
			str = str.replaceFirst("mm", String.valueOf(mm));
			str = str.replaceFirst("ss", String.valueOf(ss));
			str = str.replaceFirst("ms", String.valueOf(ms));
		} else if (format.indexOf("ss") > -1) {
			ss = (timeCount / 1000);
			ms = (timeCount % 1000);
			str = str.replaceFirst("ss", String.valueOf(ss));
			str = str.replaceFirst("ms", String.valueOf(ms));
		} else if (format.indexOf("ss") > -1) {
			ms = (timeCount % 1000);
			str = str.replaceFirst("ms", String.valueOf(ms));
		} else {
			return null;
		}
		return str;
	}

	public static String toShortString(long ms) {
		return format(ms, "HH:mm:ss");
	}

	public static String toShortStringCN(long ms) {
		return format(ms, "HH时mm分ss秒");
	}
}
